/************** init.html **************/
function queryUser_user(page) {
	sys_loading();
	var parm = $('#queryUserForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('user-query');
	sys_record_parm('user',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#userResultList').html(result);
		}
	});
}

function shieldUser_user(code, realName) {
	$.Zebra_Dialog('确定是否屏蔽'+realName + ' 用户吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
	           {caption:'屏蔽',callback:function() {
	        	   var url = create_url('user-shield');
	   				aidExecuteUser_user(code, url);
	    		}},
	           {caption:'取消',callback:function(){}
	    	}]
	});
}

function unshieldUser_user(code, realName) {
	$.Zebra_Dialog('确定要给'+realName + ' 用户解除屏蔽吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
	           {caption:'解除',callback:function() {
	        	   var url = create_url('user-unshield');
	   	    		aidExecuteUser_user(code, url);
	    		}},
	           {caption:'取消',callback:function(){}
	    	}]
	});
}

function aidExecuteUser_user(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				queryUser_user();
			} else {
				sys_msg('操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!');
			}
		}
	});
}

function selectOrganization_user() {
	var url = create_url('user-aidInit');
	var parm = {'id':'oc', 'name':'on'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}

/************** edit.html **************/


/**
 * 验证Email地址
 * @param {} email
 * @return {Boolean}
 */
function validateEmail_user(email) {
	var reEmail = /^([A-Za-z0-9])(\w)+@(\w)+(\.)(com|com\.cn|net|cn|net\.cn|org|biz|info|gov|gov\.cn|edu|edu\.cn)/;

	return email.match(reEmail) || email ==" ";
	if(email== null){
		return false;
		}
	}

function saveUser_user() {
	// 邮箱格式
	var email = $('#email').val();
	if (!validateEmail_user(email)) {
		$.Zebra_Dialog('对不起！该邮箱名【' + email + '】格式不正确!',{
			'type':	'error',
			'title': '错误'
		});
		return false;
	}
	var parm = $('#editUserForm').serialize();
	var url = create_url('user-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				sys_load_handle('user');
			} else if (result == 'exists') {
				sys_msg('对不起！邮箱名【' + email + '】已经被使用！');
			} else if (result == 'exists') {
				sys_msg('对不起！该邮箱名已经被使用！');
			} else if (result == 'no_any_rights') {
				sys_msg('没有创建角色哦！');
			} else {
				sys_msg('操作失败!');
			}
		}
	});
}

function selectReceive_user() {
	var url = create_url('m/delivery-aidQueryInit');
	var parm = {'id':'receiveCode', 'name':'receiveName'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}

function selectOrganization_user() {
	var url = create_url('user-aidInit');
	var parm = {'id':'oc', 'name':'on'};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}

function saveUserSelf_user() {
	var parm = $('#editUserSelfDiv').serialize();
	var url = create_url('user-saveSelf');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				loadDefault();
			} else {
				sys_warning('操作失败!');
			}
		}
	});
}
